package main

func countBattleships(board [][]byte) int {
	count := 0
	for i, row := range board {
		for j, point := range row {
			if point == 'X' {
				count++
				findAFleet(board, i, j)
			}
		}
	}
	return count
}

// 从 (x,y) 开始找到一支舰队，并把它们从棋盘上抹掉
// 只需要向右向下找就行
func findAFleet(board [][]byte, x, y int) {
	i := x + 1
	j := y
	for i < len(board) {
		if board[i][j] == 'X' {
			board[i][j] = '.'
		} else {
			break
		}
		i++
	}
	i = x
	j = y + 1
	for j < len(board[0]) {
		if board[i][j] == 'X' {
			board[i][j] = '.'
		} else {
			break
		}
		j++
	}
}

func main() {
	board := [][]byte {
		{'X','.','.','X'},
		{'.','.','.','X'},
		{'.','.','.','X'},
	}
	board = [][]byte {
		{'X','X','X'},
	}
	result := countBattleships(board)
	println(result)
}